const model = require('../model/userModel')

class LoginService {

  async login(req) {
    let { username, password } = req.body
    // console.log(password);
    // if (code.toLowerCase() != req.session.captcha) {
    //   return false
    // }
    let data = await model.one({ username, password })
    console.log(data);
    if (data) {
      // 登录成功 使用session保持用户登录状态
      req.session.username = data.username
      req.session.uid = data._id
      return true
    }
    return false
  }


}

module.exports = new LoginService()